import {
  DictTypeItemParams,
  DictTypeParams,
  ItemMapList,
  PageDictTypeItemModel,
  PageDictTypeModel,
} from '@/api/system/model/dictModel';
import { defHttp } from '@/utils/http/axios';

const basePath = '/system/sysDict';
const buildUrl = (url: string) => basePath + url;
enum Api {
  TypeList = '/type/pageQuery',
  TypeAddOrUpdate = '/type/addOrUpdate',
  TypeDel = '/type/del',
  TypeQueryById = '/type/queryById',
  ItemList = '/item/pageQuery',
  ItemAddOrUpdate = '/item/addOrUpdate',
  ItemDel = '/item/del',
  ItemQueryById = '/item/queryById',
  ItemMapQuery = '/item/queryAllDict',
}

export const typeList = (params: DictTypeParams) =>
  defHttp.post<PageDictTypeModel>({
    url: buildUrl(Api.TypeList),
    params: { page: params.page, pageSize: params.pageSize, t: params },
  });

export const typeAddOrEdit = (params: any) =>
  defHttp.post({ url: buildUrl(Api.TypeAddOrUpdate), params });

export const typeStatus = (id: string, status: string) =>
  defHttp.post({ url: buildUrl(Api.TypeAddOrUpdate), params: { id: id, status: status } });

export const typeDel = (id: string) => defHttp.get({ url: buildUrl(Api.TypeDel) + '/' + id });

export const typeItemList = (params: DictTypeItemParams) =>
  defHttp.post<PageDictTypeItemModel>({
    url: buildUrl(Api.ItemList),
    params: { page: params.page, pageSize: params.pageSize, t: params },
  });

export const typeItemAddOrEdit = (params: any) =>
  defHttp.post({ url: buildUrl(Api.ItemAddOrUpdate), params });

export const typeItemStatus = (id: string, status: string) =>
  defHttp.post({ url: buildUrl(Api.ItemAddOrUpdate), params: { id: id, status: status } });

export const typeItemDel = (id: string) => defHttp.get({ url: buildUrl(Api.ItemDel) + '/' + id });

export const itemMapQuery = () => defHttp.get<ItemMapList>({ url: buildUrl(Api.ItemMapQuery) });
